package com.springboot.java0317springboot.iocdemo;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 电脑类
 */
@Component
public class Computer {

    //品牌
    @Value("华为")
    private String brand;
    //cpu
    //1）属性注入
    @Qualifier("amd")
    @Autowired
    private Cpu cpu;
    //内存
    @Resource
    private Memory memory;

    public Computer(){}

    //3.构造方法注入
//    @Autowired
    public Computer(Cpu cpu,Memory memory){
        this.cpu = cpu;
        this.memory = memory;
    }
    /**
     * 开机
     */
    public void start(){
        System.out.println(brand + "电脑开机了");
        cpu.run();
        memory.read();
        memory.write();
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public Cpu getCpu() {
        return cpu;
    }

    //2.set方法注入
//    @Autowired
    public void setCpu(Cpu cpu) {
        this.cpu = cpu;
    }

    public Memory getMemory() {
        return memory;
    }

    public void setMemory(Memory memory) {
        this.memory = memory;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "brand='" + brand + '\'' +
                ", cpu=" + cpu +
                ", memory=" + memory +
                '}';
    }
}
